package edu.hitwh.controller;

import edu.hitwh.client.AuthApi;
import edu.hitwh.record.BorrowerRecord;
import edu.hitwh.record.LibrarianRecord;
import edu.hitwh.service.AuthService;
import edu.hitwh.wrapper.Resp;
import io.github.resilience4j.bulkhead.annotation.Bulkhead;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.github.resilience4j.ratelimiter.annotation.RateLimiter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
@RateLimiter(name = "default-ratelimiter")
@Bulkhead(name = "default-bulkhead")
@CircuitBreaker(name = "default-circuitbreaker")
public class AuthController implements AuthApi {
    private final AuthService authService;

    @PostMapping("/borrower")
    public Resp<Boolean> authenticateBorrower(@RequestBody BorrowerRecord borrowerRecord) {
        return Resp.success(authService.authenticateBorrower(borrowerRecord));
    }

    @PostMapping("/librarian")
    public Resp<Boolean> authenticateLibrarian(@RequestBody LibrarianRecord librarianRecord) {
        return Resp.success(authService.authenticateLibrarian(librarianRecord));
    }
}